Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

Date Property subtraction bug

#2

Reported by Paul Scott-Murphy

I saw the following stack trace just now when testing an iCalendar
file.

TypeError: expected numeric or date

   from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/

ruby/1.8/date.rb:1220:in -'<br/>

   from /Users/paulsm/Projects/ri_cal/lib/ri_cal/property_value/date.rb:

120:in send'<br/>

   from /Users/paulsm/Projects/ri_cal/lib/ri_cal/property_value/date.rb:

120:in method_missing'<br/>

   from /Users/paulsm/Projects/ri_cal/lib/ri_cal/

occurrence_enumerator.rb:163:in set_occurrence_properties!'<br/>

   from /Users/paulsm/Projects/ri_cal/lib/ri_cal/

occurrence_enumerator.rb:171:in recurrence'<br/>

   from /Users/paulsm/Projects/ri_cal/lib/ri_cal/

occurrence_enumerator.rb:105:in each'<br/>

   from /Users/paulsm/Projects/ri_cal/lib/ri_cal/

occurrence_enumerator.rb:118:in to_a'<br/>

   from /Users/paulsm/Projects/ri_cal/lib/ri_cal/

occurrence_enumerator.rb:118:in to_a'<br/>

   from /Users/paulsm/Projects/ri_cal/lib/ri_cal/

occurrence_enumerator.rb:137:in occurrences'<br/>

   from (irb):27
   from (irb):26:in `each'
   from (irb):26
   from :0

It looks like the use of method_missing in RiCal::PropertyValue::Date
isn't correct when invoking the - method, as the ::Date class requires
the argument sent to that method to be a ::Numeric or ::Date.

I added the following test for this in date_spec.rb:

describe ".-" do

 it "should return duration for two instances" do
   dt1 = RiCal::PropertyValue::Date.new(nil, :value =>

DateTime.parse("20090519"))

   dt2 = RiCal::PropertyValue::Date.new(nil, :value =>

DateTime.parse("20090518"))

   (dt1 - dt2).should == 1
 end

end

And made the test pass with this additional method in
RiCal::PropertyValue::Date

 def - (x)
   self.ruby_value - x.ruby_value
 end

There may be other instances of using the - or + methods on
RiCal::PropertyValue classes elsewhere too, which I haven't looked at.

Reported by Rick DeNatale · May 19th, 2009 @ 12:43 PM

State: resolved
Milestone: 0.0.8
Assigned to: Rick DeNatale Rick DeNatale

Activity

  1. Rick DeNatale
    Rick DeNatale

    I replied:
    Thanks Paul.

    Although there is a bug here. I'm not sure that the fix is correct,
    although I haven't had my coffee yet this morning.

    I'm pretty sure that subtracting two PropertyValue::Dates should
    result in a PropertyValue::Duration rather than an Integer.

    Could you send me the icalendar file which caused the failure?

    May 19th, 2009 @ 12:43 PM

  2. Rick DeNatale
    Rick DeNatale

    Paul later added:

    Having read through how the DateTime class handles this, I'm not sure
    that the fix is quite right now. That said, there's still a bug.

    --Paul

    May 19th, 2009 @ 12:44 PM

  3. Rick DeNatale
    Rick DeNatale

    Okay,

    date - date will now produce a duration
    date - datetime will also produce a duration
    date - duration will produce a datetime
    date + duration will produce a datetime

    May 19th, 2009 @ 04:18 PM

  4. Rick DeNatale
    Rick DeNatale
    • State changed from new to resolved
    • Milestone set to 0.0.8

    May 19th, 2009 @ 04:28 PM

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.